package cn.wit.summit.chwan.widgets;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

public class DetialRecycleview extends RecyclerView {
    public DetialRecycleview(Context context) {
        super(context);
    }

    public DetialRecycleview(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DetialRecycleview(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    MyHlistview hlistview;



    float startx = 0, starty = 0, endx = 0, endy = 0;

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
//            getParent().requestDisallowInterceptTouchEvent(true);
            startx = ev.getX();
            starty = ev.getY();
            Log.e("xxx", "scroll down");
        }
        if (ev.getAction() == MotionEvent.ACTION_MOVE) {
            if (Math.abs(startx - ev.getX()) > Math.abs(starty - ev.getY())) {
                Log.e("xxx", "scroll横向");
//                if (!hlistview.hastoch){
                getParent().requestDisallowInterceptTouchEvent(false);
                Log.e("xxx", "点击的scroll 请求夫控件拦截");
//
//                }
//                else {
//                Log.e("xxx", "点击的是子横向");
//                    getParent().requestDisallowInterceptTouchEvent(true);
//                }
            } else {

            }
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        boolean  b=super.onInterceptTouchEvent(ev);
        Log.e("xxx", "hlist onInterceptTouchEvent "+b);
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
//            if (hlistview.hastoch)
            Log.e("xxx", "scroll onInterceptTouchEvent down");
            return false;
//                return false;
        }
//        if (hlistview.hastoch)
//            return true;
        return b;
    }
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        boolean b=super.onTouchEvent(ev);
        Log.e("xxx", "scroll onTouchEvent "+b);
        if (ev.getAction() == MotionEvent.ACTION_MOVE) {
            if (Math.abs(startx - ev.getX()) > Math.abs(starty - ev.getY())) {
                Log.e("xxx", "scroll 消费掉事件");
//                getParent().requestDisallowInterceptTouchEvent(true);
            }
        }
        return b;
    }
    public void setHlistview(MyHlistview hlistivew) {
        this.hlistview=hlistivew;

    }
}
